package cn.lingyangwl.agile.infra.datamanage.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.lingyangwl.agile.infra.datamanage.mapper.*;
import cn.lingyangwl.agile.infra.datamanage.mode.entity.*;
import cn.lingyangwl.agile.infra.datamanage.mode.rqrs.*;
import cn.lingyangwl.agile.infra.datamanage.service.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 数据集的列
 *
 * @author shenguangyang
 */
@Slf4j
@Service
public class DatasetColumnServiceImpl extends ServiceImpl<DatasetColumnMapper, DatasetColumn>
    implements IService<DatasetColumn>, DatasetColumnService {

    @Override
    public List<DatasetColumn> listColumn(DatasetColumnQueryReq req) {
        if (CollUtil.isEmpty(req.getDatasetIds())) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<DatasetColumn> lqw = DatasetColumn.lqw()
            .in(CollUtil.isNotEmpty(req.getDatasetIds()), DatasetColumn::getDatasetId, req.getDatasetIds());
        return this.list(lqw);
    }

    @Override
    public void deleteColumn(List<Long> datasetId, List<Long> columnIds) {
        if (CollUtil.isEmpty(datasetId) && CollUtil.isEmpty(columnIds)) {
            return;
        }
        LambdaQueryWrapper<DatasetColumn> lqw = DatasetColumn.lqw()
            .in(CollUtil.isNotEmpty(datasetId), DatasetColumn::getDatasetId, datasetId)
            .in(CollUtil.isNotEmpty(columnIds), DatasetColumn::getId, columnIds);
        this.remove(lqw);
    }
}
